﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System;
using TransControlSystem.ViewModel.Common.Command;

namespace TransControlSystem.ViewModel.Common
{
    public class ConfirmViewModel : ViewModelBase
    {
        /// <summary>
        /// 回调消息
        /// </summary>
        public string CallbackMessage;

        /// <summary>
        /// 标题
        /// </summary>
        private string _Title;
        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            get { return _Title; }
            set
            {
                _Title = value;
                RaisePropertyChanged("Title");
            }
        }

        /// <summary>
        /// 内容
        /// </summary>
        private string _Content;
        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        {
            get { return _Content; }
            set
            {
                _Content = value;
                RaisePropertyChanged("Content");
            }
        }

        /// <summary>
        /// 确认命令
        /// </summary>
        public DelegateCommand ConfirmCommand { get; set; }

        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 构造方法
        /// </summary>
        public ConfirmViewModel()
        {
            //使用委托初始化确认命令
            ConfirmCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(ConfirmHandler)
            };
            //使用委托初始化取消命令
            CancelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CancelHandler)
            };
        }

        /// <summary>
        /// 确认方法处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void ConfirmHandler(object obj)
        {
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, CallbackMessage));
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideConfirmWindow"));
        }

        /// <summary>
        /// 取消方法
        /// </summary>
        /// <param name="obj">参数</param>
        private void CancelHandler(object obj)
        {
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideConfirmWindow"));
        }
    }
}
